// set root font size for the rem
const initFont = function () {
  if (window.$app.appType === 'mobile') {
    const dpr = window.devicePixelRatio
    const currentWidth = document.documentElement.clientWidth
    const baseWidth = 750
    let remSize = 0
    let scale = 0
    scale = currentWidth / baseWidth
    remSize = baseWidth / 10
    remSize = remSize * scale
    document.documentElement.style.fontSize = remSize + 'px'
    document.documentElement.setAttribute('data-dpr', `${dpr}`)

    window.$app.rootFontSize = remSize
  } else {
    const windowWidth = document.documentElement.clientWidth
    const baseWidth = 1920
    const baseFontSize = 37.5
    const widthRate = (windowWidth / baseWidth).toFixed(2)

    let rootFontSize = 0
    rootFontSize = parseFloat((widthRate * baseFontSize).toFixed(1))
    window.$app.widthRate = parseFloat(widthRate)

    console.log('rootFontSize:', rootFontSize)

    if (window.$app.appType === 'pad') {
      if (rootFontSize < 25) {
        rootFontSize = 25
        window.$app.widthRate = 0.8
      }
    } else {
      if (rootFontSize < 30) {
        rootFontSize = 30
        window.$app.widthRate = 0.8
      }
    }

    window.$app.rootFontSize = rootFontSize

    document.documentElement.style.fontSize = rootFontSize + 'px'
  }
}

initFont()

window.addEventListener('resize', initFont)

window.onload = initFont
